#include "Maplist.h"

Maplist::Maplist()
{
}

void Maplist::minsert(Etat* state, int cost)
{
	supa[cost].push_back(state);
	std::cout << "INSERT" << std::endl;
}

void Maplist::mdelete(Etat* state, int cost)
{
	std::list<Etat*>::iterator	it;
	for (it = supa[cost].begin(); it != supa[cost].end(); ++it)
	{
//		std::cout << "DELETE STATE : " << state << " COUT : " << cost << " VAL : " << *it << std::endl;
		if (state == *it )
		{
			std::cout << "DELETED" << std::endl;
			supa[cost].erase(it);
			break;
		}
	}
}


Etat*	Maplist::isInList(Etat* state, int cost)
{
	std::list<Etat*>::iterator	it;
	for (it = supa[cost].begin(); it != supa[cost].end(); ++it)
	{
//		std::cout << "IN LIST STATE : " << state << " COUT : " << cost << std::endl;
		if ((*state) == **it )
		{
			std::cout << "FOUND" << std::endl;
			return (*it);
			break;
		}
	}
	return(NULL);
}

/*
void Maplist::parsemap()
{
	std::map<int,list<int>>::iterator	it;

	for (it = supa.begin(); it != supa.end(); ++it)
	{
		std::cout << "CLE : " << it->first << std::endl;

		std::list<int>::iterator	at;
		for (at = it->second.begin(); at != it->second.end(); ++at)
		{
			std::cout << "==VAL : " << *at << std::endl;
		}
	}
}
*/
Etat*	Maplist::getBest()
{	
	std::map<int,list<Etat*> >::iterator	it;
	std::list<Etat*>::iterator			at;

	it = supa.begin();
	at = it->second.begin();
	if (at == it->second.end())
		return (NULL);

	std::cout << "BEST" << std::endl;
	return (*at);
}
